package org.hgvc.webapp.ets.jsf.beans.member;

import java.util.ArrayList;
import java.util.List;

import javax.faces.component.UIComponent;
import javax.faces.component.UIParameter;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import javax.faces.model.SelectItem;

import org.hgvc.webapp.ets.bo.Agreement;
import org.hgvc.webapp.ets.bo.Country;
import org.hgvc.webapp.ets.bo.DownPaymentInstallmentSchema;
import org.hgvc.webapp.ets.bo.InstallmentSchema;
import org.hgvc.webapp.ets.bo.Member;
import org.hgvc.webapp.ets.bo.MemberComp;
import org.hgvc.webapp.ets.bo.MemberInd;
import org.hgvc.webapp.ets.bo.MemberIndAcct;
import org.hgvc.webapp.ets.bo.Membership;
import org.hgvc.webapp.ets.bo.Payment;
import org.hgvc.webapp.ets.bo.PaymentDtl;
import org.hgvc.webapp.ets.bo.Race;
import org.hgvc.webapp.ets.bo.Salutation;
import org.hgvc.webapp.ets.bo.SelectObj;
import org.hgvc.webapp.ets.bo.StandingInstruction;
import org.hgvc.webapp.ets.bo.State;
import org.hgvc.webapp.ets.constant.AgreementConstant;
import org.hgvc.webapp.ets.constant.CommonConstant;
import org.hgvc.webapp.ets.constant.MemberConstant;
import org.hgvc.webapp.ets.constant.SystemConstant;
import org.hgvc.webapp.ets.spring.service.MasterSetupService;
import org.hgvc.webapp.ets.spring.service.MemberService;
import org.hgvc.webapp.ets.spring.service.MembershipService;
import org.jocsb.base.AbstractBean;
import org.jocsb.base.exception.BaseException;
import org.jocsb.base.util.BeanUtil;
import org.jocsb.base.util.SpringUtils;


public class RegistrationBean extends AbstractBean {

	public static final String BEAN_NAME="registrationBean";
	//private List<Product> productList;
	private String selectId;
	private Member member;
	private List<MemberIndAcct> dependantList;
	private MemberInd memberInd;
	private MemberComp memberComp;
	private InstallmentSchema schema;
	private MemberIndAcct memberIndAcct;
	private StandingInstruction instruction;
	private MemberService service;
	private MasterSetupService setupService;
	//private Product product;
	private List<SelectObj> typeList;
	private List<SelectObj> paymentOptionList;
	public static final String NAV_SELECT_MEMBER_TYPE = "selectMemberType";
	public static final String NAV_CREATE_IND_MEMBER = "createRegIndMember";
	public static final String NAV_CREATE_COMP_MEMBER = "createRegCompMember";
	public static final String NAV_CREATE_MEMBER_DEPENDANT = "createMemberDependant";
	public static final String NAV_CREATE_MEMBER_NOMIMEE = "createMemberNomimee";
	public static final String NAV_SELECT_PAYMENT_OPTION="selectPaymentOption";
	public static final String NAV_SELECT_INSTALLMENT_SCHEMA="selectInstallmentSchema";
	public static final String NAV_PRODUCT_PAYMENT="productPayment";
	public static final String NAV_CREATE_PROSPECT_SUCCESSFULLY="createProspectSuccess";
	public static final String NAV_SELECT_DOWN_PAYMENT="selectDownPaymentInstallmentSch";
	private String selectedType;
	private String selectedPaymentOption;
	private Payment payment;
	private PaymentDtl paymentDtl;
	private List<InstallmentSchema> schemaList;
	private double payAmt = 0;
	private Membership membership;
	private List<Membership> membershipList;
	private MembershipService membershipService;
	//
	private List<SelectItem> raceSelectList;
	private List<SelectItem> sexSelectList;
	private List<SelectItem> maritalSelectList;
	private List<SelectItem> salutationSelectList;
	private List<SelectItem> countrySelectList;
	private String indResCountryId;

	private List<SelectItem> indResStateSelectList;
	private String indMailCountryId;
	private List<SelectItem> indMailStateSelectList;
	private String indCompcountryId;
	private List<SelectItem> indCompStateSelectList;
	private String salutationId;
	private String raceId;
	private String mailSelect = CommonConstant.MAIL_SELECT_OTHER;
	private boolean mailFlag = true;
	private boolean compFlag = false;
	private List<SelectItem> mailSelectList;

	//
	private String indResStateId;
	private String indCompStateId;
	private String indMailStateId;

	//
	private String deSaluationId;
	private String deRaceId;
	private String deResCountryId;
	private String deResStateId;
	private String deCompStateId;
	private String deCompCountryId;
	private String deMailStateId;
	private String deMailCountryId;
	private List<SelectItem> deResStateSelectList;
	private List<SelectItem> deMailStateSelectList;
	private List<SelectItem> deCompStateSelectList;
	private boolean deCompFlag= false;
	private String deMailSelect;
	private boolean deMailFlag= true;
	private String password = SystemConstant.DEFAULT_PASSWORD;

	private List<SelectItem> yesNoSelectList;
	private List<SelectItem> statementTypeList;
	private List<SelectItem> compMailSelectList;
	private String compMailSelect = CommonConstant.MAIL_SELECT_OTHER;
	
	private DownPaymentInstallmentSchema downPaymentSchema;
	private List<SelectItem> downPaymentSelectList;
	private String downPaymentId;
	private List<DownPaymentInstallmentSchema> downPaymentList;
	
	private double deMonthPay=0;
	private int deMonth = 0;
	private boolean checkFlag = true;
	
	//installment
	private String schemaId;
	private double deposit=0;
	private double monthPay =0;
	private int month=0;
	private Agreement agreement;
	private String test;
	
	public double getDeMonthPay() {
		return deMonthPay;
	}

	public void setDeMonthPay(double deMonthPay) {
		this.deMonthPay = deMonthPay;
	}

	public int getDeMonth() {
		return deMonth;
	}

	public void setDeMonth(int deMonth) {
		this.deMonth = deMonth;
	}

	public String getDownPaymentId() {
		return downPaymentId;
	}
	
	public DownPaymentInstallmentSchema getDownPaymentSchema() {
		return downPaymentSchema;
	}
	public void setDownPaymentSchema(DownPaymentInstallmentSchema downPaymentSchema) {
		this.downPaymentSchema = downPaymentSchema;
	}
	public double getDeposit() {
		return deposit;
	}
	public void setDeposit(double deposit) {
		this.deposit = deposit;
	}
	public double getMonthPay() {
		return monthPay;
	}
	public void setMonthPay(double monthPay) {
		this.monthPay = monthPay;
	}
	public int getMonth() {
		return month;
	}
	public void setMonth(int month) {
		this.month = month;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	public void setMembershipService(MembershipService membershipService) {
		this.membershipService = membershipService;
	}
	public Membership getMembership() {
		return membership;
	}
	public void setMembership(Membership membership) {
		this.membership = membership;
	}

	public StandingInstruction getInstruction() {
		return instruction;
	}
	public void setInstruction(StandingInstruction instruction) {
		this.instruction = instruction;
	}
	public MemberIndAcct getMemberIndAcct() {
		return memberIndAcct;
	}
	public void setMemberIndAcct(MemberIndAcct memberIndAcct) {
		this.memberIndAcct = memberIndAcct;
	}
	public String getSelectId() {
		return selectId;
	}
	public void setSelectId(String selectId) {
		this.selectId = selectId;
	}
	public Member getMember() {
		return member;
	}
	public void setMember(Member member) {
		this.member = member;
	}
	public List<MemberIndAcct> getDependantList() {
		return dependantList;
	}
	public void setDependantList(List<MemberIndAcct> dependantList) {
		this.dependantList = dependantList;
	}
	public MemberInd getMemberInd() {
		return memberInd;
	}
	public void setMemberInd(MemberInd memberInd) {
		this.memberInd = memberInd;
	}
	public MemberComp getMemberComp() {
		return memberComp;
	}
	public void setMemberComp(MemberComp memberComp) {
		this.memberComp = memberComp;
	}
	public InstallmentSchema getSchema() {
		return schema;
	}

	public MemberService getService() {
		return service;
	}
	public void setService(MemberService service) {
		this.service = service;
	}
	public MasterSetupService getSetupService() {
		return setupService;
	}
	public void setSetupService(MasterSetupService setupService) {
		this.setupService = setupService;
	}
	public void setTypeList(List<SelectObj> typeList) {
		this.typeList = typeList;
	}

	public void setPaymentOptionList(List<SelectObj> paymentOptionList) {
		this.paymentOptionList = paymentOptionList;
	}
	public Payment getPayment() {
		return payment;
	}
	public void setPayment(Payment payment) {
		this.payment = payment;
	}
	public PaymentDtl getPaymentDtl() {
		return paymentDtl;
	}
	public void setPaymentDtl(PaymentDtl paymentDtl) {
		this.paymentDtl = paymentDtl;
	}

	public void setSchemaList(List<InstallmentSchema> schemaList) {
		this.schemaList = schemaList;
	}
	public double getPayAmt() {
		return payAmt;
	}
	public void setPayAmt(double payAmt) {
		this.payAmt = payAmt;
	}
	public String getIndResCountryId() {
		return indResCountryId;
	}
	public void setIndResCountryId(String indResCountryId) {
		this.indResCountryId = indResCountryId;
	}
	public String getIndMailCountryId() {
		return indMailCountryId;
	}
	public void setIndMailCountryId(String indMailCountryId) {
		this.indMailCountryId = indMailCountryId;
	}
	public String getIndCompcountryId() {
		return indCompcountryId;
	}
	public void setIndCompcountryId(String indCompcountryId) {
		this.indCompcountryId = indCompcountryId;
	}

	public String getSalutationId() {
		return salutationId;
	}
	public void setSalutationId(String salutationId) {
		this.salutationId = salutationId;
	}
	public String getMailSelect() {
		return mailSelect;
	}
	public boolean isMailFlag() {
		return mailFlag;
	}
	public void setMailFlag(boolean mailFlag) {
		this.mailFlag = mailFlag;
	}

	public boolean isCompFlag() {
		return compFlag;
	}
	public void setCompFlag(boolean compFlag) {
		this.compFlag = compFlag;
	}

	public String getRaceId() {
		return raceId;
	}
	public void setRaceId(String raceId) {
		this.raceId = raceId;
	}
	public String getDeSaluationId() {
		return deSaluationId;
	}
	public void setDeSaluationId(String deSaluationId) {
		this.deSaluationId = deSaluationId;
	}
	public String getDeRaceId() {
		return deRaceId;
	}
	public void setDeRaceId(String deRaceId) {
		this.deRaceId = deRaceId;
	}
	public String getDeResCountryId() {
		return deResCountryId;
	}
	public void setDeResCountryId(String deResCountryId) {
		this.deResCountryId = deResCountryId;
	}
	public String getDeResStateId() {
		return deResStateId;
	}
	public void setDeResStateId(String deResStateId) {
		this.deResStateId = deResStateId;
	}
	public String getDeCompStateId() {
		return deCompStateId;
	}
	public void setDeCompStateId(String deCompStateId) {
		this.deCompStateId = deCompStateId;
	}
	public String getDeCompCountryId() {
		return deCompCountryId;
	}
	public void setDeCompCountryId(String deCompCountryId) {
		this.deCompCountryId = deCompCountryId;
	}
	public String getDeMailStateId() {
		return deMailStateId;
	}
	public void setDeMailStateId(String deMailStateId) {
		this.deMailStateId = deMailStateId;
	}
	public String getDeMailCountryId() {
		return deMailCountryId;
	}
	public void setDeMailCountryId(String deMailCountryId) {
		this.deMailCountryId = deMailCountryId;
	}
	public boolean isDeCompFlag() {
		return deCompFlag;
	}
	public void setDeCompFlag(boolean deCompFlag) {
		this.deCompFlag = deCompFlag;
	}
	public boolean isDeMailFlag() {
		return deMailFlag;
	}
	public void setDeMailFlag(boolean deMailFlag) {
		this.deMailFlag = deMailFlag;
	}
	public String getDeMailSelect() {
		return deMailSelect;
	}
	public String getIndResStateId() {
		return indResStateId;
	}
	public void setIndResStateId(String indResStateId) {
		this.indResStateId = indResStateId;
	}
	public String getIndCompStateId() {
		return indCompStateId;
	}
	public void setIndCompStateId(String indCompStateId) {
		this.indCompStateId = indCompStateId;
	}
	public String getIndMailStateId() {
		return indMailStateId;
	}
	public void setIndMailStateId(String indMailStateId) {
		this.indMailStateId = indMailStateId;
	}
	//--------------------------------------------------------------
	public List<SelectObj> getTypeList() {

		SelectObj indMember = new SelectObj();
		indMember.setId(CommonConstant.MEMBER_TYPE_IND);
		indMember.setTitle(SpringUtils.getMessage(CommonConstant.MEMBER_TYPE_IND, new Object[]{}));

		SelectObj corMember = new SelectObj();
		corMember.setId(CommonConstant.MEMBER_TYPE_COMP);
		corMember.setTitle(SpringUtils.getMessage(CommonConstant.MEMBER_TYPE_COMP, new Object[]{}));

		typeList = new ArrayList<SelectObj>();
		typeList.add(indMember);
		typeList.add(corMember);

		return typeList;
	}
	public List<Membership> getMembershipList() {
		try{
			membershipList = membershipService.getMembershipList();
		}catch(BaseException be){
			be.printStackTrace();
			initErrorBean(be);
		}
		return membershipList;
	}

	public void registrationListener(ActionEvent actionevent){
		UIParameter param = (UIParameter)actionevent.getComponent().findComponent("membershipId");
		selectId = (String)param.getValue();
		for(Membership mem:membershipList){
			if(mem.getMembershipId().equalsIgnoreCase(selectId)){
				this.membership = mem;
				break;
			}
		}
	}

	public String navSelectMemberType(){
		return NAV_SELECT_MEMBER_TYPE;
	}

	public void createMemberListener(ActionEvent actionevent){
		UIParameter param = (UIParameter)actionevent.getComponent().findComponent("memberType");
		selectedType = (String)param.getValue();
	}

	public String getSelectedType() {
		return selectedType;
	}

	public void setSelectedType(String selectedType) {
		this.selectedType = selectedType;
	}

	public String navCreateMember(){
		member = new Member();
		member.setRegistrationType(MemberConstant.MEMBER_REG_ONLINE);
		if(selectedType.equalsIgnoreCase(CommonConstant.MEMBER_TYPE_IND)){
			member.setMemberType(CommonConstant.MEMBER_TYPE_IND);
			memberInd = new MemberInd();
			dependantList = new ArrayList<MemberIndAcct>();
			return NAV_CREATE_IND_MEMBER;
		}else{
			member.setMemberType(CommonConstant.MEMBER_TYPE_COMP);
			memberComp = new MemberComp();
			dependantList = new ArrayList<MemberIndAcct>();
			return NAV_CREATE_COMP_MEMBER;
		}
	}

	public String navCreateDependant(){
		memberIndAcct = new MemberIndAcct();
		return NAV_CREATE_MEMBER_DEPENDANT;
	}

	public String navCreateNomimee(){
		memberIndAcct = new MemberIndAcct();
		return NAV_CREATE_MEMBER_NOMIMEE;
	}
	
	public String createNomimeeAction(){
		if(dependantList.size()==membership.getMembershipCategory().getDependantLimitInt()){
			initErrorBean(SpringUtils.getMessage("error.dependant.limit", new Object[]{}));
			return NAV_CREATE_MEMBER_NOMIMEE;
		}
		//validate dependant ic no
		for(MemberIndAcct dependant:dependantList){
			if(dependant.getNewIcNo().equalsIgnoreCase(memberIndAcct.getNewIcNo())){
				initErrorBean(SpringUtils.getMessage("error.duplicate.ic.no.dependant.found", new Object[]{}));
				return NAV_CREATE_MEMBER_NOMIMEE;
			}
		}
		
		if(deMailCountryId!=null&&deMailCountryId.length()>0)
			memberIndAcct.setMailCountry(new Country(deMailCountryId));
		if(deMailStateId!=null&&deMailStateId.length()>0)
			memberIndAcct.setMailState(new State(deMailStateId));
		if(deCompCountryId!=null&&deCompCountryId.length()>0)
			memberIndAcct.setCompCountry(new Country(deCompCountryId));
		if(deCompStateId!=null&&deCompStateId.length()>0)
			memberIndAcct.setCompState(new State(deCompStateId));
		if(deResCountryId!=null&&deResCountryId.length()>0)
			memberIndAcct.setResCountry(new Country(deResCountryId));
		if(deResStateId!=null&&deResStateId.length()>0)
			memberIndAcct.setResState(new State(deResStateId));
		if(deRaceId!=null&&deRaceId.length()>0)
			memberIndAcct.setRace(new Race(deRaceId));
		if(deSaluationId!=null&&deSaluationId.length()>0){
			memberIndAcct.setSalutation(new Salutation(deSaluationId));
		}

		MemberIndAcct newDependant = new MemberIndAcct();
		BeanUtil.copyFields(memberIndAcct, newDependant, true);
		memberIndAcct = new MemberIndAcct();
		dependantList.add(newDependant);
		return NAV_CREATE_COMP_MEMBER;
	}
	
	public String createDependantAction(){

		if(dependantList.size()==membership.getMembershipCategory().getDependantLimitInt()){
			initErrorBean(SpringUtils.getMessage("error.dependant.limit", new Object[]{}));
			return NAV_CREATE_MEMBER_DEPENDANT;
		}

		//validate dependant ic no
		for(MemberIndAcct dependant:dependantList){
			if(dependant.getNewIcNo().equalsIgnoreCase(memberIndAcct.getNewIcNo())){
				initErrorBean(SpringUtils.getMessage("error.duplicate.ic.no.dependant.found", new Object[]{}));
				return NAV_CREATE_MEMBER_DEPENDANT;
			}
		}

		if(deMailCountryId!=null&&deMailCountryId.length()>0)
			memberIndAcct.setMailCountry(new Country(deMailCountryId));
		if(deMailStateId!=null&&deMailStateId.length()>0)
			memberIndAcct.setMailState(new State(deMailStateId));
		if(deCompCountryId!=null&&deCompCountryId.length()>0)
			memberIndAcct.setCompCountry(new Country(deCompCountryId));
		if(deCompStateId!=null&&deCompStateId.length()>0)
			memberIndAcct.setCompState(new State(deCompStateId));
		if(deResCountryId!=null&&deResCountryId.length()>0)
			memberIndAcct.setResCountry(new Country(deResCountryId));
		if(deResStateId!=null&&deResStateId.length()>0)
			memberIndAcct.setResState(new State(deResStateId));
		if(deRaceId!=null&&deRaceId.length()>0)
			memberIndAcct.setRace(new Race(deRaceId));
		if(deSaluationId!=null&&deSaluationId.length()>0){
			memberIndAcct.setSalutation(new Salutation(deSaluationId));
		}

		MemberIndAcct newDependant = new MemberIndAcct();
		BeanUtil.copyFields(memberIndAcct, newDependant, true);
		memberIndAcct = new MemberIndAcct();
		dependantList.add(newDependant);
		return NAV_CREATE_IND_MEMBER;
	}

	public String selectPaymentOption(){
		return NAV_SELECT_PAYMENT_OPTION;
	}

	public List<SelectObj> getPaymentOptionList() {

		SelectObj packageObj = new SelectObj();
		packageObj.setId(MemberConstant.MEMBER_PAYMENT_FULL_PACKAGE);
		packageObj.setTitle(SpringUtils.getMessage(MemberConstant.MEMBER_PAYMENT_FULL_PACKAGE, new Object[]{}));

		SelectObj installObj = new SelectObj();
		installObj.setId(MemberConstant.mEMBER_PAYMENT_INSTALLMET_SCHEMA);
		installObj.setTitle(SpringUtils.getMessage(MemberConstant.mEMBER_PAYMENT_INSTALLMET_SCHEMA, new Object[]{}));

		paymentOptionList = new ArrayList<SelectObj>();
		paymentOptionList.add(packageObj);
		paymentOptionList.add(installObj);

		return paymentOptionList;
	}

	public void paymentListener(ActionEvent actionEvent){
		UIParameter param = (UIParameter)actionEvent.getComponent().findComponent("paymentSelectId");
		selectedPaymentOption = (String)param.getValue();
	}

	public String navCreatePayment(){
		//member.setPaymentMethod(selectedPaymentOption);
		instruction = new StandingInstruction();
		
		if(member.getMemberType().equalsIgnoreCase(CommonConstant.MEMBER_TYPE_COMP)){
			if(indMailCountryId!=null&&indMailCountryId.length()>0)
				memberComp.setMailCountry(new Country(indMailCountryId));
			if(indMailStateId!=null&&indMailStateId.length()>0)
				memberComp.setMailState(new State(indMailStateId));
			if(indCompcountryId!=null&&indCompcountryId.length()>0)
				memberComp.setRegCountry(new Country(indCompcountryId));
			if(indCompStateId!=null&&indCompStateId.length()>0)
				memberComp.setRegState(new State(indCompStateId));
		}else{
			if(indMailCountryId!=null&&indMailCountryId.length()>0)
				memberInd.setMailCountry(new Country(indMailCountryId));
			if(indMailStateId!=null&&indMailStateId.length()>0)
				memberInd.setMailState(new State(indMailStateId));
			if(indCompcountryId!=null&&indCompcountryId.length()>0)
				memberInd.setCompCountry(new Country(indCompcountryId));
			if(indCompStateId!=null&&indCompStateId.length()>0)
				memberInd.setCompState(new State(indCompStateId));
			if(indResCountryId!=null&&indResCountryId.length()>0)
				memberInd.setResCountry(new Country(indResCountryId));
			if(indResStateId!=null&&indResStateId.length()>0)
				memberInd.setResState(new State(indResStateId));
			if(raceId!=null&&raceId.length()>0)
				memberInd.setRace(new Race(raceId));
		}
		//
		
		//
		if(selectedPaymentOption.equalsIgnoreCase(MemberConstant.MEMBER_PAYMENT_FULL_PACKAGE)){
			payAmt = membership.getMembershipFeeDbl();
			return NAV_PRODUCT_PAYMENT;
		}else{
			return NAV_SELECT_INSTALLMENT_SCHEMA;
		}
	}

	public List<InstallmentSchema> getSchemaList() {
		try{
			schemaList = setupService.getInstallmentSchemaList();
		}catch(BaseException be){
			be.printStackTrace();
			initErrorBean(be);
		}
		return schemaList;
	}

	/*public void createSchemaListener(ActionEvent actionEvent){
		UIParameter param = (UIParameter)actionEvent.getComponent().findComponent("schemaId");
		String id = (String)param.getValue();
		for(InstallmentSchema schema:schemaList){
			if(schema.getInstallmentSchemaId().equalsIgnoreCase(id)){
				this.schema = schema;
				member.setSchema(schema);
				payAmt = membership.getMembershipFeeDbl()*(schema.getDepositPercentDbl()/100);
				break;
			}
		}
	}*/

	public String navSchemaCreatePayment(){
		instruction = new StandingInstruction();
		return NAV_PRODUCT_PAYMENT;
	}

	public void paymentSchemaActionListener(ActionEvent actionEvent){
		if(downPaymentSchema!=null){
			payAmt = deMonthPay;
		}else{
			payAmt = deposit;
		}
	}


	public String confirmPaymentAction(){
		try{
			payment = new Payment();
			paymentDtl = new PaymentDtl();
			agreement = new Agreement();
			agreement.setMembership(this.membership);
			agreement.setRegType(AgreementConstant.AGREEMENT_PUBLIC_REG);
			if(schema==null&&downPaymentSchema==null){
				agreement.setPaymentType(AgreementConstant.AGREEMENT_PAYMENT_FULL_PACKAGE);
			}else if(schema!=null&&downPaymentSchema==null){
				agreement.setPaymentType(AgreementConstant.AGREEMENT_PAYMENT_INSTALLMENT_PACKAGE);
				agreement.setInstallmentSchema(schema);
			}else if(schema!=null&&downPaymentSchema!=null){
				agreement.setInstallmentSchema(schema);
				agreement.setDownPaymentInstallmentSchema(downPaymentSchema);
				agreement.setPaymentType(AgreementConstant.AGREEMENT_PAYMENT_INSTALLMENT_DEPOSIT_PACKAGE);
			}
			
			if(selectedType.equalsIgnoreCase(CommonConstant.MEMBER_TYPE_IND)){
				payment = service.createProspectIndividualMember(member, memberInd, dependantList, null, payment, paymentDtl,instruction,agreement,payAmt);
			}else{
				payment = service.createProspectCompMember(member, memberComp, null, dependantList,payment, paymentDtl,instruction,agreement,payAmt);
			}
			return NAV_CREATE_PROSPECT_SUCCESSFULLY;
		}catch(BaseException be){
			be.printStackTrace();
			initErrorBean(be);
		}
		return NAV_PRODUCT_PAYMENT;
	}
	public List<SelectItem> getIndResStateSelectList() {
		try{
			indResStateSelectList = new ArrayList<SelectItem>();
			if(indResCountryId!=null&&indResCountryId.length()>0){
				List<State> sList = setupService.getStateList(indResCountryId);
				for(State s:sList){
					SelectItem item = new SelectItem(s.getStateId(),s.getDesc());
					indResStateSelectList.add(item);
				}
			}
		}catch(BaseException be){
			be.printStackTrace();
			initErrorBean(be);
		}
		return indResStateSelectList;
	}
	public List<SelectItem> getIndMailStateSelectList() {
		try{
			indMailStateSelectList = new ArrayList<SelectItem>();
			if(indMailCountryId!=null&&indMailCountryId.length()>0){
				List<State> sList = setupService.getStateList(indMailCountryId);
				for(State s:sList){
					SelectItem item = new SelectItem(s.getStateId(),s.getDesc());
					indMailStateSelectList.add(item);
				}
			}
		}catch(BaseException be){
			be.printStackTrace();
			initErrorBean(be);
		}
		return indMailStateSelectList;
	}
	public List<SelectItem> getIndCompStateSelectList() {
		try{
			indCompStateSelectList = new ArrayList<SelectItem>();
			if(indCompcountryId!=null&&indCompcountryId.length()>0){
				List<State> sList = setupService.getStateList(indCompcountryId);
				for(State s:sList){
					SelectItem item = new SelectItem(s.getStateId(),s.getDesc());
					indCompStateSelectList.add(item);
				}
			}
		}catch(BaseException be){
			be.printStackTrace();
			initErrorBean(be);
		}
		return indCompStateSelectList;
	}
	public List<SelectItem> getRaceSelectList() {
		try{
			List<Race> rList = setupService.getRaceList();
			raceSelectList= new ArrayList<SelectItem>();
			for(Race r:rList){
				SelectItem item = new SelectItem(r.getRaceId(),r.getDesc());
				raceSelectList.add(item);
			}
		}catch(BaseException be){
			be.printStackTrace();
			initErrorBean(be);
		}
		return raceSelectList;
	}
	public List<SelectItem> getSexSelectList() {
		sexSelectList = new ArrayList<SelectItem>();
		for(String[] array:CommonConstant.genderSelectList){
			SelectItem item = new SelectItem(array[0],SpringUtils.getMessage(array[1],new Object[]{}));
			sexSelectList.add(item);
		}
		return sexSelectList;
	}
	public List<SelectItem> getMaritalSelectList() {
		maritalSelectList = new ArrayList<SelectItem>();
		for(String[] array:CommonConstant.maritalStatusSelectList){
			SelectItem item = new SelectItem(array[0],SpringUtils.getMessage(array[1],new Object[]{}));
			maritalSelectList.add(item);
		}
		return maritalSelectList;
	}
	public List<SelectItem> getSalutationSelectList() {
		try{
			List<Salutation> sList = setupService.getSalutationList();
			salutationSelectList= new ArrayList<SelectItem>();
			for(Salutation s:sList){
				SelectItem item = new SelectItem(s.getSalutationId(),s.getDesc());
				salutationSelectList.add(item);
			}
		}catch(BaseException be){
			be.printStackTrace();
			initErrorBean(be);
		}
		return salutationSelectList;
	}
	public List<SelectItem> getCountrySelectList() {
		try{
			List<Country> cList = setupService.getCountryList();
			countrySelectList= new ArrayList<SelectItem>();
			for(Country c:cList){
				SelectItem item = new SelectItem(c.getCountryId(),c.getDesc());
				countrySelectList.add(item);
			}
		}catch(BaseException be){
			be.printStackTrace();
			initErrorBean(be);
		}
		return countrySelectList;
	}
	public List<SelectItem> getMailSelectList() {

		mailSelectList = new ArrayList<SelectItem>();
		for(String[] array:CommonConstant.MAIL_SELECT_LIST){
			SelectItem item = new SelectItem(array[0],SpringUtils.getMessage(array[1],new Object[]{}));
			mailSelectList.add(item);
		}

		return mailSelectList;
	}
	public void setMailSelect(String mailSelect) {
		if(mailSelect.equalsIgnoreCase(CommonConstant.MAIL_SELECT_OTHER)){
			mailFlag = false;
			compFlag = false;
		}else{
			mailFlag = true;
			if(mailSelect.equalsIgnoreCase(CommonConstant.MAIL_SELECT_COMP)){
				memberInd.setMailAddress1(memberInd.getCompAddress1());
				memberInd.setMailAddress2(memberInd.getCompAddress2());
				memberInd.setMailPostcode(memberInd.getCompPostcode());
				memberInd.setMailCity(memberInd.getCompCity());
				memberInd.setMailCountry(memberInd.getCompCountry());
				memberInd.setMailState(memberInd.getCompState());
				compFlag = true;
			}else if(mailSelect.equalsIgnoreCase(CommonConstant.MAIL_SELECT_RES)){
				memberInd.setMailAddress1(memberInd.getResAddress1());
				memberInd.setMailAddress2(memberInd.getResAddress2());
				memberInd.setMailPostcode(memberInd.getResPostcode());
				memberInd.setMailCity(memberInd.getResCity());
				memberInd.setMailCountry(memberInd.getResCountry());
				memberInd.setMailState(memberInd.getResState());
				compFlag = false;
			}
		}
		this.mailSelect = mailSelect;
	}
	public List<SelectItem> getDeResStateSelectList() {
		try{
			deResStateSelectList = new ArrayList<SelectItem>();
			if(deResCountryId!=null&&deResCountryId.length()>0){
				List<State> sList = setupService.getStateList(deResCountryId);
				for(State s:sList){
					SelectItem item = new SelectItem(s.getStateId(),s.getDesc());
					deResStateSelectList.add(item);
				}
			}
		}catch(BaseException be){
			be.printStackTrace();
			initErrorBean(be);
		}
		return deResStateSelectList;
	}
	public List<SelectItem> getDeMailStateSelectList() {
		try{
			deMailStateSelectList = new ArrayList<SelectItem>();
			if(deMailCountryId!=null&&deMailCountryId.length()>0){
				List<State> sList = setupService.getStateList(deMailCountryId);
				for(State s:sList){
					SelectItem item = new SelectItem(s.getStateId(),s.getDesc());
					deMailStateSelectList.add(item);
				}
			}
		}catch(BaseException be){
			be.printStackTrace();
			initErrorBean(be);
		}
		return deMailStateSelectList;
	}
	public List<SelectItem> getDeCompStateSelectList() {
		try{
			deCompStateSelectList = new ArrayList<SelectItem>();
			if(deCompCountryId!=null&&deCompCountryId.length()>0){
				List<State> sList = setupService.getStateList(deMailCountryId);
				for(State s:sList){
					SelectItem item = new SelectItem(s.getStateId(),s.getDesc());
					deCompStateSelectList.add(item);
				}
			}
		}catch(BaseException be){
			be.printStackTrace();
			initErrorBean(be);
		}
		return deCompStateSelectList;
	}
	public void setDeMailSelect(String deMailSelect) {
		if(deMailSelect.equalsIgnoreCase(CommonConstant.MAIL_SELECT_OTHER)){
			deMailFlag = false;
			deCompFlag = false;
		}else{
			deMailFlag = true;
			if(deMailSelect.equalsIgnoreCase(CommonConstant.MAIL_SELECT_COMP)){
				memberIndAcct.setMailAddress1(memberIndAcct.getCompAddress1());
				memberIndAcct.setMailAddress2(memberIndAcct.getCompAddress2());
				memberIndAcct.setMailPostcode(memberIndAcct.getCompPostcode());
				memberIndAcct.setMailCity(memberIndAcct.getCompCity());
				memberIndAcct.setMailCountry(memberIndAcct.getCompCountry());
				memberIndAcct.setMailState(memberIndAcct.getCompState());
				deCompFlag = true;
			}else if(deMailSelect.equalsIgnoreCase(CommonConstant.MAIL_SELECT_RES)){
				memberIndAcct.setMailAddress1(memberIndAcct.getResAddress1());
				memberIndAcct.setMailAddress2(memberIndAcct.getResAddress2());
				memberIndAcct.setMailPostcode(memberIndAcct.getResPostcode());
				memberIndAcct.setMailCity(memberIndAcct.getResCity());
				memberIndAcct.setMailCountry(memberIndAcct.getResCountry());
				memberIndAcct.setMailState(memberIndAcct.getResState());
				deCompFlag = false;
			}
		}
		this.deMailSelect = deMailSelect;
	}

	public void removeDependantListener(ActionEvent actionEvent){
		UIParameter param = (UIParameter)actionEvent.getComponent().findComponent("dependantId");
		String dependantId = (String)param.getValue();
		for(MemberIndAcct ind:dependantList){
			if(ind.getNewIcNo().equalsIgnoreCase(dependantId)){
				dependantList.remove(ind);
				break;
			}
		}
	}

	public void setSchema(InstallmentSchema schema) {
		this.schema = schema;
	}
	public String getSchemaId() {
		return schemaId;
	}
	public void setSchemaId(String schemaId) {
		try{
			this.schemaId = schemaId;
			if(schemaId!=null){
				for(InstallmentSchema sch:schemaList){
					if(sch.getInstallmentSchemaId().equalsIgnoreCase(schemaId)){
						double fee = membership.getMembershipFeeDbl();
						deposit = fee*(sch.getDepositPercentDbl()/100);
						monthPay = (fee - deposit)/sch.getMonthInt();
						monthPay = (Math.round(monthPay*100.0))/100.0;
						month = sch.getMonthInt();
						schema = sch;
						/*payAmt = deposit;*/
						break;
					}
				}
			}
		}catch(Exception ex){
			ex.printStackTrace();
		}
	}

	public List<SelectItem> getSchemaSelectList(){
		List<SelectItem> list = new ArrayList<SelectItem>();
		for(InstallmentSchema sch:getSchemaList()){
			SelectItem item = new SelectItem(sch.getInstallmentSchemaId(),sch.getCode()+" "+sch.getName());
			list.add(item);
		}
		return list;
	}
	public List<SelectItem> getYesNoSelectList() {
		yesNoSelectList = new ArrayList<SelectItem>();
		for(String[] str:CommonConstant.yesnoSelectList){
			SelectItem item = new SelectItem(str[0],SpringUtils.getMessage(str[1], new Object[]{}));
			yesNoSelectList.add(item);
		}

		return yesNoSelectList;
	}
	public List<SelectItem> getStatementTypeList() {

		statementTypeList = new ArrayList<SelectItem>();
		SelectItem item = new SelectItem(MemberConstant.MEMBER_STATEMENT_IND,SpringUtils.getMessage(MemberConstant.MEMBER_STATEMENT_IND, new Object[]{}));
		SelectItem item1 = new SelectItem(MemberConstant.MEMBER_STATEMENT_COMB,SpringUtils.getMessage(MemberConstant.MEMBER_STATEMENT_COMB, new Object[]{}));
		statementTypeList.add(item);
		statementTypeList.add(item1);
		return statementTypeList;
	}

	public List<SelectItem> getCompMailSelectList() {

		compMailSelectList = new ArrayList<SelectItem>();
		for(String[] array:CommonConstant.MAIL_COMP_OTHER_SELECT_LIST){
			SelectItem item = new SelectItem(array[0],SpringUtils.getMessage(array[1],new Object[]{}));
			compMailSelectList.add(item);
		}

		return compMailSelectList;
	}
	public void setCompMailSelectList(List<SelectItem> compMailSelectList) {
		this.compMailSelectList = compMailSelectList;
	}
	public void setCompMailSelect(String compMailSelect) {
		if(compMailSelect.equalsIgnoreCase(CommonConstant.MAIL_SELECT_OTHER)){
			mailFlag = false;
			compFlag = false;
		}else{
			mailFlag = true;
			if(compMailSelect.equalsIgnoreCase(CommonConstant.MAIL_SELECT_COMP)){
				memberComp.setMailAddress1(memberComp.getRegAddress1());
				memberComp.setMailAddress2(memberComp.getRegAddress2());
				memberComp.setMailPostcode(memberComp.getRegPostcode());
				memberComp.setMailCity(memberComp.getRegCity());
				memberComp.setMailCountry(memberComp.getRegCountry());
				memberComp.setMailState(memberComp.getRegState());
				compFlag = true;
			}
		}
		this.compMailSelect = compMailSelect;
	}
	public String getCompMailSelect() {
		return compMailSelect;
	}
	
	
	public String navSelectDownPaymentAction(){
		return NAV_SELECT_DOWN_PAYMENT;
	}
	
	public String removeDownPaymentAction(){
		downPaymentSchema = null;
		return NAV_SELECT_INSTALLMENT_SCHEMA;
	}
	
	public String navSelectInstallmentSch(){
		return NAV_SELECT_INSTALLMENT_SCHEMA;
	}
	
	public List<SelectItem> getDownPaymentSelectList(){
		downPaymentSelectList = new ArrayList<SelectItem>();
		try{
			downPaymentList = setupService.getDownPaymentInstallmentSchemaList();
			for(DownPaymentInstallmentSchema downPayment:downPaymentList){
				SelectItem item = new SelectItem(downPayment.getDownPaymentInstallmentSchemaId(),downPayment.getName());
				downPaymentSelectList.add(item);
			}
			
		}catch(BaseException be){
			be.printStackTrace();
			initErrorBean(be);
		}
		return downPaymentSelectList;
	}
	
	public void setDownPaymentId(String downPaymentId) {
		this.downPaymentId = downPaymentId;
		for(DownPaymentInstallmentSchema sch:downPaymentList){
			if(sch.getDownPaymentInstallmentSchemaId().equalsIgnoreCase(downPaymentId)){
				deMonth = sch.getMonthInt();
				deMonthPay = deposit/deMonth;
				deMonthPay = (Math.round(deMonthPay*100.0))/100.0;
				downPaymentSchema = sch;
				break;
			}
		}
	}
	

	public boolean isCheckFlag() {
		return checkFlag;
	}

	public String getTest() {
		return test;
	}

	public void setTest(String test) {
		this.test = test;
	}

	public void setCheckFlag(boolean checkFlag) {
		this.checkFlag = checkFlag;
	}
	
	public void validator(FacesContext context,UIComponent comp,Object obj){
		String value = (String)obj;
		if(value.equalsIgnoreCase("1")){
			checkFlag = false;
		}else{
			checkFlag = true;
		}
	}
	
}
